package com.chen106106.sstest.common.struts2;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;

import com.opensymphony.xwork2.config.ConfigurationManager;

public class IndexActionMapper extends DefaultActionMapper {

	@Override
	public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) {
		String uri = request.getRequestURI();
		if (StringUtils.equals(uri, "") || StringUtils.endsWith(uri, "/")) {
			ActionMapping mapping = new ActionMapping();
			mapping.setNamespace(StringUtils.stripEnd(uri, "/"));
			mapping.setName("index");
			return mapping;
		}
		return super.getMapping(request, configManager);
	}
}
